import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { MountBaseEntity } from "./mount-base.entity";

@Entity("character_mounts")
@ManualTimestamp()
export class CharacterMountEntity {
  @PrimaryGeneratedColumn({ comment: "玩家坐骑ID" })
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { comment: "坐骑基础ID" })
  mountBaseId!: number;

  @Column("int", { default: 1, comment: "坐骑等级" })
  level!: number;

  @Column("int", { default: 0, comment: "坐骑经验值" })
  experience!: number;

  @Column("int", { default: 0, comment: "转职等级" })
  transLevel!: number;

  @Column("tinyint", {
    default: 0,
    comment: "是否上阵：0-休息，1-休息，2-出战" })
  status!: number;

  // 当前等级的属性值（基于基础数据计算）
  @Column("int", { default: -1000, comment: "当前攻击力" })
  currentAp!: number;

  @Column("int", { default: -1000, comment: "当前生命值" })
  currentHp!: number;

  @Column("int", { default: -1000, comment: "当前法力值" })
  currentMp!: number;

  @Column("int", { default: -1000, comment: "当前速度" })
  currentSp!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", comment: "更新时间", nullable: true })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  @ManyToOne(() => MountBaseEntity)
  @JoinColumn({ name: "mountBaseId" })
  mountBase!: MountBaseEntity;
}
